package dao.impl;

import bean.Test;
import dao.mapper.TestMapper;
import dao.TestDAO;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository(value = "dao")
public class TestDAOImpl extends SqlSessionDaoSupport implements TestDAO {
    public TestDAOImpl(@Autowired SqlSessionFactory sessionFactory) {
        setSqlSessionFactory(sessionFactory);
    }

    @Override
    public int add(String field2) {
        return getSqlSession().getMapper(TestMapper.class).ins(field2);
    }

    @Override
    public int mod(Test test) {
        return getSqlSession().getMapper(TestMapper.class).upd(test);
    }

    @Override
    public int rem(int field1) {
        return getSqlSession().getMapper(TestMapper.class).del(field1);
    }

    @Override
    public Test que(int field1) {
        return getSqlSession().getMapper(TestMapper.class).selById(field1);
    }

    @Override
    public List<Test> que(String keywords) {
        return getSqlSession().getMapper(TestMapper.class).selByNam(keywords);
    }
}
